package com.hl.controller.coupon;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hl.domain.CouponActivity;
import com.hl.service.ICouponActivityService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 券活动信息Controller
 * 
 * @author ruoyi
 * @date 2025-08-08
 */
@RestController
@RequestMapping("/activity")
public class CouponActivityController extends BaseController
{
    @Autowired
    private ICouponActivityService couponActivityService;

    /**
     * 查询券活动信息列表
     */
    @RequiresPermissions("coupon:activity:list")
    @GetMapping("/list")
    public TableDataInfo list(CouponActivity couponActivity)
    {
        startPage();
        List<CouponActivity> list = couponActivityService.selectCouponActivityList(couponActivity);
        return getDataTable(list);
    }

    /**
     * 导出券活动信息列表
     */
    @RequiresPermissions("coupon:activity:export")
    @Log(title = "券活动信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CouponActivity couponActivity)
    {
        List<CouponActivity> list = couponActivityService.selectCouponActivityList(couponActivity);
        ExcelUtil<CouponActivity> util = new ExcelUtil<CouponActivity>(CouponActivity.class);
        util.exportExcel(response, list, "券活动信息数据");
    }

    /**
     * 获取券活动信息详细信息
     */
    @RequiresPermissions("coupon:activity:query")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Integer activityId)
    {
        return success(couponActivityService.selectCouponActivityByActivityId(activityId));
    }

    /**
     * 新增券活动信息
     */
    @RequiresPermissions("coupon:activity:add")
    @Log(title = "券活动信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CouponActivity couponActivity)
    {
        return toAjax(couponActivityService.insertCouponActivity(couponActivity));
    }

    /**
     * 修改券活动信息
     */
    @RequiresPermissions("coupon:activity:edit")
    @Log(title = "券活动信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CouponActivity couponActivity)
    {
        return toAjax(couponActivityService.updateCouponActivity(couponActivity));
    }

    /**
     * 删除券活动信息
     */
    @RequiresPermissions("coupon:activity:remove")
    @Log(title = "券活动信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Integer[] activityIds)
    {
        return toAjax(couponActivityService.deleteCouponActivityByActivityIds(activityIds));
    }
}
